const api = require('../../../utils/interface.js')
const math = require('../../../utils/math.js')
const tools = require('../../../utils/util.js')
Page({
  data: {
    details: {},
    cardName: "",
    src: ""
  },
  onLoad: function(options) {
    console.log(options)
    this.getConsumption(options.orderNumber)
    let cardName = wx.getStorageSync('userInfo').name
    this.setData({
      cardName: cardName
    })
  },
  // 获取消费订单明细
  getConsumption(orderNumber) {
    api.getOrder({
      orderNumber
    }).then(res => {
      console.log(res.data.result)
      res.data.result.createTime_ = tools.formatTime(new Date(res.data.result.createTime))
      res.data.result.orderAmount_ = math.divide(res.data.result.orderAmount, 100)
      res.data.result.payAmount_ = math.divide(res.data.result.payAmount, 100)
      res.data.result.couponAmount_ = math.divide(res.data.result.couponAmount, 100)
      res.data.result.downAmount = math.divide(Number(res.data.result.downAmount), 100)
      res.data.result.redPackedAmount = math.divide(Number(res.data.result.redPackedAmount), 100)
      res.data.result.rebateAmount = math.divide(Number(res.data.result.rebateAmount), 100)
      res.data.result.fullReductionAmount = math.divide(Number(res.data.result.fullReductionAmount), 100)
      res.data.result.payType_ = ""
      res.data.result.rise = math.divide(res.data.result.orderAmount_, math.divide(res.data.result.oilPrice, 100)).toFixed(2)
      switch (res.data.result.payType) {
        case '1':
          res.data.result.payType_ = '支付宝'
          this.data.src = '/static/zfb.png'
          break;
        case '2':
          res.data.result.payType_ = '微信'
          this.data.src = '/static/wechat.png'
          break;
        case '3':
          res.data.result.payType_ = '银联'
          this.data.src = '/static/yl.png'
          break;
        case '4':
          res.data.result.payType_ = '余额'
          this.data.src = '/static/ye.png'
          break;
        case '5':
          res.data.result.payType_ = '现金'
          this.data.src = '/static/xj.png'
          break;
        case '6':
          res.data.result.payType_ = '一网通'
          break;
      }
      switch (res.data.result.invoiceStatus) {
        case '0':
          res.data.result.invoiceStatusName = "未开"
          break;
        case '1':
          res.data.result.invoiceStatusName = "已开"
          break;
        case '2':
          res.data.result.invoiceStatusName = "不可开"
          break;

      }
      this.setData({
        details: res.data.result,
        src: this.data.src
      })
    })
  },

  onShow: function() {

  },
})